import Api from './Api';

class CtyunApi extends Api<CtyunApi> {
  get prefix() {
    return `devops/ctyun/v1/projects/${this.projectId}`;
  }

  getSiteSteps() {
    return this.request({
      url: `${this.prefix}/ci_template_step/list/with/category`,
      method: 'get',
    });
  }

  getProjectList() {
    return this.request({
      url: `${this.prefix}/ci_template_job_group/list`,
      method: 'get',
    });
  }

  getProjectSteps() {
    return this.request({
      url: `${this.prefix}/ci_template_step_category`,
      method: 'get',
    });
  }

  checkJobName(name: string, id?: any) {
    return this.request({
      url: `${this.prefix}/ci_template_job/check_name`,
      method: 'get',
      params: {
        name,
        job_id: id,
      },
    });
  }

  checkStepName(name: string, id?: any) {
    return this.request({
      url: `${this.prefix}/ci_template_step/check/name/unique`,
      method: 'get',
      params: {
        name,
        template_step_id: id,
      },
    });
  }
}

const ctyunApi = new CtyunApi();
const ctyunApiConfig = new CtyunApi(true);
export { ctyunApiConfig, ctyunApi };
